package classfile

import "math"

// CONSTANT_Integer_info {
//	 u1 tag;
//	 u4 bytes;
// }
type ConstantIntegerInfo struct {
	val int32
}

// 读取一个uint32数据，然后把它转型成int32类型
func (self *ConstantIntegerInfo) readInfo(reader *ClassReader) {
	var bytes = reader.readUint32()
	self.val = int32(bytes)
}
func (self *ConstantIntegerInfo) Value() int32 {
	return self.val
}

// CONSTANT_Float_info {
//    u1 tag;
//    u4 bytes;
// }
type ConstantFloatInfo struct {
	val float32
}

// 读取一个uint32数据，然后把它转型成float32类型
func (self *ConstantFloatInfo) readInfo(reader *ClassReader) {
	var bytes = reader.readUint32()
	self.val = math.Float32frombits(bytes)
}

func (self *ConstantFloatInfo) Value() float32 {
	return self.val
}

//CONSTANT_Long_info {
//    u1 tag;
//    u4 high_bytes;
//    u4 low_bytes;
//}
type ConstantLongInfo struct {
	val int64
}

// 读取一个uint64数据，然后把它转型成int64类型
func (self *ConstantLongInfo) readInfo(reader *ClassReader) {
	var bytes = reader.readUint64()
	self.val = int64(bytes)
}

func (self *ConstantLongInfo) Value() int64 {
	return self.val
}

//CONSTANT_Double_info {
//    u1 tag;
//    u4 high_bytes;
//    u4 low_bytes;
//}
type ConstantDoubleInfo struct {
	val float64
}

// 读取一个uint64数据，然后把它转型成float64类型
func (self *ConstantDoubleInfo) readInfo(reader *ClassReader) {
	var bytes = reader.readUint64()
	self.val = math.Float64frombits(bytes)
}

func (self *ConstantDoubleInfo) Value() float64 {
	return self.val
}
